<?php JHTML::_('behavior.formvalidation'); ?>
<?php $editor = JFactory::getEditor(); ?>
<!--[if IE 9]> 
<link rel="stylesheet" href="components/com_mail/public/css/ie9.css" type="text/css" />
<![endif]-->
<!--[if IE 8]> 
<link rel="stylesheet" href="components/com_mail/public/css/ie8.css" type="text/css" />
<![endif]-->

<style>
.ZebraDialog{
    top: 60px !important;
}
</style>


<form action="index.php?option=com_mail" method="post" name="adminForm" class="form-validate" id="item-form">
	
    <div class="div-information" >
      <table border=0 class="table-information">
        <tr>
            <td></td>
            <td><span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;text-align: left;">※印は入力必須項目です。</span></td>
        </tr>
        <tr valign="top">
            <td style="width:10% ;">
                <label class="right" for="jformMAMA_MAGR_CODE">配信先<span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;">※</span></td>
            </td>
            <td width="400px">
                <textarea rows="1" style="width: 660px; height: 70px;"  id="jformMAMA_MAGR_CODE" name="jform[MAMA_MAGR_CODE]"><?php echo $this->row->MAMA_MAGR_CODE ?></textarea>
            </td>
            <td><input id="btnMAMA_MAGR_CODE" type="button" value="配信先選択" /></td>
        </tr>
        <tr>
            <td>
                <label for="jformMAMA_TITLE" class="right">件名<span class="err">※</span></label>
            </td>
            <td>
                <input style="width: 400px;" type="text" id="jformMAMA_TITLE" value="<?php echo $this->row->MAMA_TITLE ?>" name="jform[MAMA_TITLE]" class="inputbox bigx" size="30" />
            </td>
        </tr>
         <tr valign="top">
            <td>
                <label class="right">予定送信日</label>
            </td>
            
            <td colspan="2">
                <table width="100%">
                <tr valign="top">
                    <td style="width:10%;" id="type-user">
                        <?php 
                        if(!isset($this->row->MAMA_TYPE)){ $this->row->MAMA_TYPE = 1; }
                        $MAMA_TYPE = HelperBG::getMAMA_TYPE();
                        foreach($MAMA_TYPE as $k=>$v){
                            $checked = null;
                            if($this->row->MAMA_TYPE == $k){
                                $checked = "checked='checked'";
                            }
                            echo "<p>
                                    <input id='rdMAMA_TYPE$k' class='rdMAMA_TYPE' type='radio' value='$k' name='jform[MAMA_TYPE]' $checked />
                                    <label for='rdMAMA_TYPE$k'>$v</label>
                                </p>";
                        }
                        //echo JHTML::_('select.radiolist',$MAMA_TYPE, 'jform[MAMA_TYPE]', null, 'key', 'value', $this->row->MAMA_TYPE );
                        ?>
                        
                    </td>
                    <td width="50%" >
                        <?php 
                        if(!$this->row->MAMA_DATETIME){
                            $this->row->MAMA_DATETIME = date('Y/m/d h:i:s');
                            //echo $this->row->MAMA_DATETIME;
                        }
                        $year = array( date('Y')=>date('Y'),date('Y')+1=>date('Y')+1,date('Y')+2=>date('Y')+2 );
                        echo JHTML::_('Select.genericlist',$year,"jform[year]",'onchange="setDays(this,jformmonth,jformday)"',null,null,date('Y', strtotime($this->row->MAMA_DATETIME)));
                        ?>年 
                        
                        <?php 
                        $month = array( 1=>1, 2=>2,3=>3, 4=>4,5=>5, 6=>6,7=>7, 8=>8,9=>9, 10=>10,11=>11, 12=>12 );
                        echo JHTML::_('Select.genericlist',$month,"jform[month]",'onchange="setDays(jformyear,this,jformday)"',null,null,date('n', strtotime($this->row->MAMA_DATETIME)));
                        ?>月 
                        
                        <?php 
                        $day = array( 1=>1, 2=>2,3=>3, 4=>4,5=>5, 6=>6,7=>7, 8=>8,9=>9, 10=>10, 
                                        11=>11, 12=>12,13=>13, 14=>14,15=>15, 16=>16,17=>17, 18=>18,19=>19, 20=>20,
                                        21=>21, 22=>22,23=>23, 24=>24,25=>25, 26=>26,27=>27, 28=>28,29=>29, 30=>30, 31=>31);
                        echo JHTML::_('Select.genericlist',$day,"jform[day]",'onchange="setDays(jformyear,jformmonth,this)"',null,null,date('j', strtotime($this->row->MAMA_DATETIME)));
                        ?>日 
                        
                        <?php 
                        $hour = array(  '00'=>'00', '01'=>'01', '02'=>'02','03'=>'03', '04'=>'04','05'=>'05', '06'=>'06','07'=>'07', '08'=>'08','09'=>'09', 10=>10,11=>11, 12=>12,
                                        13=>13, 14=>14,15=>15, 16=>16,17=>17, 18=>18,19=>19, 20=>20,21=>21,22=>22,23=>23 );
                        echo JHTML::_('Select.genericlist',$hour,"jform[hour]",'',null,null,date('H', strtotime($this->row->MAMA_DATETIME)));
                        ?>時
                        
                        <?php 
                        $min = array(  '00'=>'00',15=>15, 30=>30,45=>45);
                        echo JHTML::_('Select.genericlist',$min,"jform[min]",'',null,null,date('i', strtotime($this->row->MAMA_DATETIME)));
                        ?>分
                    </td>
                </tr>
                </table>
            </td>
            
            
            
            <td>
            </td>
        </tr>
      <tr>
        <td></td>
        <td><input type="checkbox" value="1" name="jform[MAMA_REJECT]" id="jformMAMA_REJECT" checked="checked"/>
            <label for="jformMAMA_REJECT">メールの配信停止リンクを添付する</label>
        </td>
      </tr>
        <tr>
        </tr>
        <tr>
        </tr>
        <tr style="vertical-align: top">
            <td ><label class="right" >メールマガジン本文<span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;">※</span></label></td>
            <td colspan="2">
                <?php 
                    echo $editor->display('jform[MAMA_BODY]', $this->row->MAMA_BODY, '800', '400', '60', '20', false);
                  ?>
            </td>
        </tr>
      </table><br/>
       
        
		</tbody>
	</table>

   
    <input name="task" type="hidden"/>
    <input name="jform[MAMA_CODE]" type="hidden" value="<?php echo $this->row->MAMA_CODE ?>" />
</form>

<script type="text/javascript">
    
    jq('.rdMAMA_TYPE').click(function(){
        if(jq(this).val() == 3){
            jq('#jformyear').attr("disabled", true);
            jq('#jformmonth').attr("disabled", true);
            jq('#jformday').attr("disabled", true);
            jq('#jformhour').attr("disabled", true);
            jq('#jformmin').attr("disabled", true); 
            jq('#jformMAMA_MAGR_CODE, #btnMAMA_MAGR_CODE,#jformyear').attr('readonly', 'readonly','readonly').addClass('readonly');

            if(!jq('#jformMAMA_MAGR_CODE').val()){
                jq('#jformMAMA_MAGR_CODE').val('指導員更新用');
            }
        }else if(jq(this).val() == 2){
            jq('#jformyear').attr("disabled", true);
            jq('#jformmonth').attr("disabled", true);
            jq('#jformday').attr("disabled", true);
            jq('#jformhour').attr("disabled", true);
            jq('#jformmin').attr("disabled", true);
            jq('#jformMAMA_MAGR_CODE, #btnMAMA_MAGR_CODE').removeAttr('readonly').removeClass('readonly');
        }
        else{
            jq('#jformyear').attr("disabled", false);
            jq('#jformmonth').attr("disabled", false);
            jq('#jformday').attr("disabled", false);
            jq('#jformhour').attr("disabled", false);
            jq('#jformmin').attr("disabled", false);
        }
    })
    /*
	Joomla.submitbutton = function(task){
	   
       if(task == 'savetemp'){
	       Joomla.submitform(task, document.getElementById('item-form'));
	   }else{
	       if ( task == 'cancel' || document.formvalidator.isValid(document.id('item-form'))) {
                // if MAMA_TYPE isn't send now, it won't validate date
                if(!jq('#rdMAMA_TYPE2').attr('checked') && task != 'cancel'){
                    var date = new Date(
                        document.getElementById('jformyear').value,
                        document.getElementById('jformmonth').value-1,
                        document.getElementById('jformday').value,
                        document.getElementById('jformhour').value,
                        document.getElementById('jformmin').value
                    );
                    if(date <= new Date()){
                        alert('メールの送信期間が調整ではない');
                        return false;
                    }
                    
                    // submit form if it is valid and date is valid
                    Joomla.submitform(task, document.getElementById('item-form'));
                }else{ // else it is sent now, not check date
                    Joomla.submitform(task, document.getElementById('item-form'));
                }
            } else { // form invalid
                alert('不明な情報');
            }
        }
		
	}

*/
    /*Joomla.submitbutton=function(a){
        if(jq('.invalid').length){
            alert('Invalid form');
        }else{
            Joomla.submitform(a);
        }
    };*/
</script>

<script>
    jq(document).ready(function() {
        // show a dialog box when clicking on a link
        jq('#btnMAMA_MAGR_CODE').bind('click', function(e) {
            e.preventDefault();
            jq.Zebra_Dialog('', {
                source:  {'ajax': 'index.php?option=com_popup&view=bg&task=popup&tmpl=component'},
                /*source: {'iframe': {
                    
                    'src':  'index.php?option=com_popup&view=bg&task=popup&tmpl=component',
                    'height': 450
                }},*/
                height: 750,
                width: 850,
                title:  '配信先選択',
                type:  '',
                buttons:  [
                    {caption: 'キャンセル', callback: function() {}},
                    {caption: 'OK', callback: function() {
                        jq('#jformMAMA_MAGR_CODE').val(jq('#jformMAMA_MAGR_CODE').val()+jq('#list_uid').val());
                    }
                        
                    }
                ]
            });
        });   
                        
     });
</script>
